/*
Problem Id:1032  User Id:tq 
Memory:44K  Time:31MS
Language:C++  Result:Accepted

	author: TangQiao , Wind @ Beijing Normal University

	problem name: Globetrotter
	
	source : BNU Online Judge / ulm 1997
	
	problem type: 几何 公式推导
	
	problem description: 已知地球半径和经纬度,求两点之间的最小弧长(即以球心为圆心的弧).
	
	problem solution: 将点的极坐标转换成x, y, z 坐标,然后可以由余弧定理
						c*c=a*a+b*b-2abcos(@)
						可以将夹角算法,最后求出弧长.
	
	award & note : 1. 转换成X,Y,Z坐标时不用乘以R,因为我们只是需要用它来最后算夹角而已.
	               2. 最后的余弧公式可以化简,最后成了:
						dd=city[a].x*city[b].x+city[a].y*city[b].y+city[a].z*city[b].z;
	
	
	date : 2005.7.12 北师大校队个人练习赛4
	
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#define pi  (3.141592653589793)
#define r (6378)

struct ty
{
	char name[40];
	double x,y,z;
}city[200];
int ncity;


double dis(int a, int b)
{
	double jiao, dd;
	dd=city[a].x*city[b].x+city[a].y*city[b].y+city[a].z*city[b].z;
	jiao=acos(dd);
	return jiao*r;
}

main()
{
	char in[40];
	char s1[40],s2[40];
	int i;
	double a,b;
	ncity=0;
	while (1)
	{
		scanf("%s", in);
		if (in[0]=='#') break;
		ncity++;
		strcpy(city[ncity].name,in);
		scanf("%lf%lf", &a, &b);
		a=a*pi/180;
		b=b*pi/180;
		city[ncity].x=cos(a)*cos(b);
		city[ncity].y=cos(a)*sin(b);
		city[ncity].z=sin(a);
	}

	while (1)
	{
		int a,b,find;

		scanf("%s%s", s1,s2);
		find=1;
		if (s1[0]=='#') break;
		for (i=1;i<=ncity;i++)
			if (strcmp(s1,city[i].name)==0)
			{
				a=i;
				break;
			}
		if (i==ncity+1) find=0;
		for (i=1;i<=ncity;i++)
			if (strcmp(s2,city[i].name)==0)
			{
				b=i;
				break;
			}
		if (i==ncity+1) find=0;
		printf("%s - %s\n", s1,s2);
		if (!find) printf("Unknown\n\n");
		else if (a==b) printf("0 km\n\n");
		else printf("%.0lf km\n\n",dis(a,b));

	}
	

	return 0;
}